package com.af.security.configurer;

import com.af.data.jpa.entity.AfAuditorAware;
import com.af.security.auth.user.data.AfAuditorUser;
import com.af.security.property.JwtProperties;
import com.af.security.property.LdapProperties;
import com.af.security.property.ProjectProperties;
import com.af.security.property.SecurityProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author : zhenyun.su
 * @comment :
 * @since : 2019/7/25
 */

@Configuration
@ConditionalOnClass({PasswordEncoder.class, AfAuditorUser.class, AfAuditorAware.class})
@EnableConfigurationProperties({ProjectProperties.class, JwtProperties.class, SecurityProperties.class, LdapProperties.class})
public class AfSecurityAutoConfigurer {

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public AfAuditorUser afAuditorUser(){
        return new AfAuditorUser();
    }

    @Bean
    public AfAuditorAware afAuditorAware(){
        return new AfAuditorAware(afAuditorUser());
    }

    // @Autowired
    // private UserService userService;
    //
    // @Autowired
    // private SecurityProperties securityProperties;
    // @Autowired
    // private Cache<String, AfUserDetails> securityCache;
    //
    // @Bean
    // @ConditionalOnMissingBean
    // // @ConditionalOnProperty(prefix = "szy.service", value = "enabled", havingValue = "true")
    // public LockedUserHandler lockedUserHandler(){
    //     return new LockedUserHandler(securityCache, userService, securityProperties);
    // }

}
